<?php
/*
 * CCache类
 * @author andery <andery@foxmail.com>
 * @link http://www.Nimo.com/
 * @version $Id: CCache.lib.php 2010-07-29 11:27:10Z andery $
 */
class CCache{
    protected static $_cache_server = null;
    public function __construct($cache_type)
    {
        CLang::load('lib.Cache');
        if (empty($cache_type)) {
            $cache_type = CConf::get('cache.cache_type');
        }
        require_once( dirname(__FILE__) . '/cache/ICache.php');
        $cache_class = 'C' . trim($cache_type) . 'Cache';
        require_once( dirname(__FILE__) . '/cache/' . $cache_class . '.php');
        $config = CConf::get('cache.' . trim($cache_type));
        if (class_exists($cache_class)) {
            $cache = new $cache_class();
            $cache->connect($config);
        } else {
            throw new CException(CLang::get('cache_type_invalid'));
        }
        self::$_cache_server = $cache;
    }
    
    public function getInstance($cache_type)
    {
        if (!self::$_cache_server) {
    	    new self($cache_type);
    	}
		return self::$_cache_server;
    }
    
    private function __clone(){}
}